{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-06-25T06:57:26.901985Z",
     "start_time": "2025-06-25T06:57:26.203712Z"
    }
   },
   "source": [
    "from langchain_ollama import OllamaEmbeddings\n",
    "\n",
    "from jupyter_constants import OLLAMA_DEFAULT_MODEL\n",
    "\n",
    "embeddings = OllamaEmbeddings(\n",
    "    model=OLLAMA_DEFAULT_MODEL,\n",
    "    temperature=0.5,\n",
    ")"
   ],
   "outputs": [],
   "execution_count": 9
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-25T06:57:26.913877Z",
     "start_time": "2025-06-25T06:57:26.901985Z"
    }
   },
   "cell_type": "code",
   "source": [
    "f = open(\"a_story.txt\", \"r\", encoding=\"utf-8\")\n",
    "content = f.read()\n",
    "f.close()"
   ],
   "id": "148f17dbecedb8b0",
   "outputs": [],
   "execution_count": 10
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-25T06:58:01.756732Z",
     "start_time": "2025-06-25T06:57:26.916158Z"
    }
   },
   "cell_type": "code",
   "source": [
    "input_text = content\n",
    "\n",
    "vector = embeddings.embed_query(input_text)\n",
    "f\"{vector[:3]}\""
   ],
   "id": "e9a050477f598d95",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'[-0.0036686615, -0.008164262, -0.0025820057]'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-25T06:59:48.192770Z",
     "start_time": "2025-06-25T06:59:47.517518Z"
    }
   },
   "cell_type": "code",
   "source": [
    "input_texts = [\"Document 1...\", \"Document 2...\"]\n",
    "vectors = embeddings.embed_documents(input_texts)\n",
    "f\"length of vector: {len(vectors)}\""
   ],
   "id": "811567d2d24b9956",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'length of vector: 2'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 13
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-25T06:59:49.042122Z",
     "start_time": "2025-06-25T06:59:49.029662Z"
    }
   },
   "cell_type": "code",
   "source": "f\"vectors[0][:3]: {vectors[0][:3]}\"",
   "id": "5a9252d549591c43",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'vectors[0][:3]: [0.002104413, -0.0026944256, 0.0009686252]'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 14
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-25T06:59:50.227669Z",
     "start_time": "2025-06-25T06:59:50.213120Z"
    }
   },
   "cell_type": "code",
   "source": "f\"vectors[1][:3]: {vectors[1][:3]}\"",
   "id": "1719ecf99f2d0390",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'vectors[1][:3]: [0.0024464028, -0.0018452876, -0.00030305973]'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 15
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
